<template>
  <div>
    <a-card :bordered="false">
      <f-search-form :more="false" @searchHandler="searchHandler">
        <f-search-form-item label="标题" name="sliderTitle"/>
        <f-search-form-item label="类型" name="sliderType" type="select" :data="api.slider.sliderType"></f-search-form-item>
      </f-search-form>
      <f-table ref="table" size="default" rowKey="sliderId" :columns="columns" :multiple="false" :operator="operator" :params="queryParam" :api="api.slider">
          <span slot="sliderImg" slot-scope="text, record, index">
            <img :src="record.sliderImg" v-viewer class="radius-img">
           </span>
        <span slot="sendStatus" slot-scope="text, record, index">
          <a-switch v-model="record.sendStatus==1" checkedChildren="已发布" unCheckedChildren="未发布" @change="(checked) => setStatus(checked,record)"/>
        </span>
        <span slot="action" slot-scope="text, record">
          <template>
            <a @click="$refs.modal.showDrawer(record)">编辑</a>
            <a-divider type="vertical"/>
          </template>
          <a-dropdown>
            <a class="ant-dropdown-link">
              更多 <a-icon type="down"/>
            </a>
            <a-menu slot="overlay">
              <a-menu-item v-if="$auth('table.delete')">
                <a href="javascript:;" @click="$refs.table.remove(record.sliderId)">删除</a>
              </a-menu-item>
            </a-menu>
          </a-dropdown>
        </span>
      </f-table>
      <slider-drawer ref="modal"></slider-drawer>
    </a-card>
  </div>
</template>
<script>
  import SliderDrawer from './slider_drawer'
  import api from './js/api'
  export default {
    name: 'TableList',
    components: {
      SliderDrawer
    },
    data() {
      let me = this
      //操作按钮
      let operator = []
      operator.push({
        name: '添加',
        icon: 'plus',
        that: this,
        handler: function(table, that) {
          that.$refs.modal.showDrawer()
        }
      })
      operator.push({
        name: '删除',
        icon: 'delete',
        batch: true,
        handler: function(table) {
          table.remove()
        }
      })
      return {
        //列表初始化查询参数
        queryParam: {},
        api:api,
        // 表头
        columns: [
          {
            title: '#',
            width: '60',
            align: 'center',
            customRender: (text, record, index) => index + 1
          },
          {
            title: '封面图',
            align: 'center',
            scopedSlots: { customRender: 'sliderImg' }
          },
          {
            title: '标题',
            dataIndex: 'sliderTitle'
          },
          {
            title: '跳转方式',
            dataIndex: 'jumpType',
            customRender: function(text) {
              return me.columnFormatter(me.api.slider.jumpType, text)
            }
          },
          {
            title: '发布状态',
            align: 'center',
            scopedSlots: { customRender: 'sendStatus' }
          },
          {
            title: '发布类型',
            align: 'center',
            dataIndex: 'sliderType',
            customRender: function(text) {
              return me.columnFormatter(me.api.slider.sliderType, text)
            }
          },
          {
            title: '排序号',
            dataIndex: 'sortOrder'
          },
          {
            title: '操作',
            dataIndex: 'action',
            scopedSlots: { customRender: 'action' }
          }
        ],
        operator: operator
      }
    },
    created() {
    },
    methods: {
      //设置发布状态
      setStatus(check, record) {
        this.http.post(this, {
          url: this.api.slider.setSendStatus,
          data: {
            ids: record.sliderId,
            sendStatus: Number(check)
          },
          success(me, data) {
            record.sendStatus = data
          }
        })
      }
    }
  }
</script>
